<a id="openApp" style="display:none;">打开App</a>
<h1 style="text-align:center;">DeepLinkTest</h1>
<div id="info" style="text-align:center; margin-top:20px;"></div>

<script>
    window.addEventListener('DOMContentLoaded', function () {
        const currentUrl = new URL(window.location.href);
        const infoDiv = document.getElementById('info');
        infoDiv.innerHTML = `
            <strong>Current URL:    </strong> ${currentUrl.origin + currentUrl.pathname}<br>
        `;

        // 获取当前地址，用来 callback
        openApp.href = `link://www.example.com?callback=${window.location.href}#want;S.market_referrer=store%3A%2F%2Fappgallery.huawei.com%2Fapp%2Fdetail%3Fid%3DbundleName;S.browser_fallback_url=http%3A%2F%2Fwww.baidu.com;end`;
        console.log('---href---: ', openApp.href);

        // 解析 hash 参数，判断是初次打开还是 recall ，分别处理
        const hashParams = new URLSearchParams(window.location.hash.substring(1));
        let recall = hashParams.get('recall');
        console.log('------reacall----------: ' , typeof recall, recall);
        if (hashParams.has('recall') && hashParams.get('recall') === 'true') {
            alert(hashParams.get('data'));
        } else {
            setTimeout(function () {
                document.getElementById('openApp').click();
            }, 1000);   // 1 秒
        }
    });

</script>